//删除的id
$('#startTime').datetimepicker({
	minView: "month",
	language: 'zh-CN',
	format: 'yyyy-mm-dd',
	todayBtn: 1,
	autoclose: true
});
$('#endTime').datetimepicker({
	minView: "month",
	language: 'zh-CN',
	format: 'yyyy-mm-dd',
	todayBtn: 1,
	autoclose: true
});
var oprateUrl = DOMAIN + '/v1/orderPurchase' + isLogin;
function loadTable() {
	$("#table").bootstrapTable({ // 对应table标签的id
		url: oprateUrl,
		method: 'get',
		cache: false,
		striped: true,
		pagination: true,
		pageSize: 50,
		pageNumber: 1,
		pageList: [50,100],
		search: false,
		showColumns: false,
		clickToSelect: true,
		queryParams: {
			deleteFlg: 0
		},
		smartDisplay: false,
		columns: [{
			field: "id",
			title: "id",
			align: "center",
			valign: "middle",
			sortable: "true",
			visible: false
		}, {
			field: "outDate",
			title: "出库日期",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "salesOrder",
			title: "销售订单号",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "customerName",
			title: "客户名称",
			align: "center",
			valign: "middle",
			sortable: "true"
		},{
			field: "productName",
			title: "商品名称",
			align: "center",
			valign: "middle",
			sortable: "true"
		},{
			field: "productLevelOne",
			title: "一级类型",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "productLevelTwo",
			title: "二级类型",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "salesPrice",
			title: "订单单价",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "units",
			title: "单位",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "salesAmount",
			title: "订单数量",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "salesMoney",
			title: "订单总金额",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "purchaseNo",
			title: "采购单号",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "supplierName",
			title: "供应商名称",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "purchasePrice",
			title: "采购价格",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "outAmount",
			title: "出库数量",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "purchaseMoney",
			title: "采购金额",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "purchaseMoneyAll",
			title: "采购总额",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "margin",
			title: "毛利",
			align: "center",
			valign: "middle",
			sortable: "true"
		}, {
			field: "marginRate",
			title: "毛利率",
			align: "center",
			valign: "middle",
			sortable: "true"
		}/*,{
			field: "",
			title: "操作",
			align: "center",
			valign: "middle",
			events: funOprate,
			formatter: function (value, row, index) {
				if (row.deleteFlg == 1) {
					return '<button storageNo="' + row.storageNo + '" type="button" data-toggle="modal" data-edit="myModal" data-target="#myModal" onclick="EditInfo(this)" class="btn btn-primary btn-sm edit">编辑</button>';
				} else {
					return '<button storageNo="' + row.storageNo + '" type="button" data-toggle="modal" data-edit="myModal" data-target="#myModal" onclick="EditInfo(this)" class="btn btn-primary btn-sm edit">&emsp;查看</button> <button data-del="' + oprateUrl + '" class="btn btn-primary btn-sm del">&emsp;删除</button>';
				}
			}
		}*/],
		//>>>>>>>>>>>>>>导出excel表格设置
		showExport: true,
		//是否显示导出按钮
		buttonsAlign: "left",
		//按钮位置
		exportDataType: 'all',
		//导出的方式 all全部 selected已选择的  basic', 'all', 'selected'.
		Icons: 'glyphicon glyphicon-export',
		exportTypes: ['excel', 'doc', 'xlsx', 'txt',],
		//导出文件类型
		exportOptions: {
			ignoreColumn: [0, 0],  //忽略某一列的索引，id删除更新用用，不显示与导出

			fileName: '销售采购详情',
			//文件名称设置
			worksheetName: 'sheet1',
			//表格工作区名称
			tableName: '销售采购详情',
			// excelstyles: ['background-color', 'color', 'font-size', 'font-weight'], 设置格式

		},
		//导出excel表格设置<<<<<<<<<<<<<<<<
		formatNoMatches: function () {
			return '没有找到匹配的记录';
		}
	});
}

//查询
$("#selectPurchaseBtn").click(function () {
	//新查询参数
	function queryParamNew(params) {
		var params = {};
		params.startTime = $("#startTime").val();
		params.endTime = $("#endTime").val();
		params.salesOrder = $("#orderNo").val();
		return params;
	};
	var url = DOMAIN + '/v1/orderPurchase' + isLogin;
	$('#table').bootstrapTable(
		'refreshOptions',
		{
			url: url,
			//查询参数
			queryParams: queryParamNew
		}
	);
})

$(function(){
	time_rota2($("#startTime"));
	time_rota($("#endTime"));	
	loadTable();
	//新查询参数
	function queryParamNew(params) {
		var params = {};
		params.startTime = $("#startTime").val();
		params.endTime = $("#endTime").val();
		params.salesOrder = $("#orderNo").val();
		return params;
	};
	var url = DOMAIN + '/v1/orderPurchase' + isLogin;
	$('#table').bootstrapTable(
		'refreshOptions',
		{
			url: url,
			//查询参数
			queryParams: queryParamNew
		}
	);
});
